package com.example.algorithm.tree.uf;

import java.util.Scanner;

public class TestUFTREEWeighted {

    public static void main(String[] args) {

        //创建并查集对象
        UF_TREE_Weighted uf = new UF_TREE_Weighted(5);
        //录入要合并的元素
        Scanner scanner = new Scanner(System.in);
        System.out.println("原有"+uf.count());

        while (true){
            System.out.println("1:");
            int p = scanner.nextInt();
            System.out.println("2:");
            int q = scanner.nextInt();

            if (uf.connected(q,p)){
                System.out.println("同一组"+p+"     "+q);
                continue;
            }

            uf.union(p,q);
            System.out.println("uf count"+uf.count());
        }
    }
}
